package com.cljz.peipei.base;


import com.clzj.peipei.bean.UserInfo;
import com.clzj.peipei.dao.DaoSession;
import com.clzj.peipei.dao.UserInfoDao;
import com.google.gson.Gson;

import cn.droidlover.xdroidmvp.cache.SharedPref;
import cn.droidlover.xdroidmvp.mvp.IView;
import cn.droidlover.xdroidmvp.mvp.XPresent;
import de.greenrobot.dao.query.Query;

/**
 * Created by apple on 2017/4/5.
 */

public class BaseP<V extends IView> extends XPresent<V> {
    protected Gson gson;
    protected DaoSession daoSession = ((App) App.instance).getDaoSession();

    public BaseP() {
        gson = new Gson();
    }




    public String getToken() {
        return SharedPref.getInstance(App.getInstance()).getString(Constant.TOKEN, "");
    }
    public void putToken(String token) {
        SharedPref.getInstance(App.getInstance()).putString(Constant.TOKEN, token);
    }

    public UserInfo getUserInfo(String token) {
        UserInfo userInfo = null;
        Query<UserInfo> query = daoSession.getUserInfoDao().queryBuilder()
                .where(UserInfoDao.Properties.Token.eq(token))
                .build();
        if (query.list().size() > 0) {
            userInfo = query.list().get(0);
        }
        return userInfo;
    }

}
